<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:ctrls="clr-namespace:BreadcrumbLib.Controls"
    xmlns:bc="clr-namespace:BreadcrumbLib.BaseControls"
    xmlns:uc="clr-namespace:BreadcrumbLib.Controls.Breadcrumbs"
    xmlns:conv="clr-namespace:BreadcrumbLib.Converters"
    >
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Geometry.xaml" />
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Buttons.xaml" />

    <ResourceDictionary Source="/BreadcrumbLib;component/Controls/Breadcrumbs/BreadcrumbTreeItem.xaml" />
    <ResourceDictionary Source="/BreadcrumbLib;component/Themes/Default/Brushes.xaml" />
		<!-- ResourceDictionary Source="/BreadcrumbLib;component/Controls/Breadcrumbs/BreadcrumbExpander.xaml" / -->
  </ResourceDictionary.MergedDictionaries>

  <Style TargetType="{x:Type uc:BreadcrumbTree}">
    <!--<Setter Property="Background" Value="Gray"></Setter>-->
    <!-- Setter Property="ItemTemplate" Value="{StaticResource {x:Type uc:BreadcrumbTreeItem}}" / -->
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="ItemContainerStyle">
      <Setter.Value>
        <Style TargetType="{x:Type uc:BreadcrumbTreeItem}">
          <Setter Property="Background" Value="Transparent"/>
          <Setter Property="BorderThickness" Value="1" />
          <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" />
          <Setter Property="OverflowedItemContainerStyle" Value="{Binding OverflowedItemContainerStyle, 
                RelativeSource={RelativeSource AncestorType={x:Type uc:BreadcrumbTree}}}" />
          <!--<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>-->
          <Setter Property="Padding" Value="1,0,0,0"/>
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type uc:BreadcrumbTreeItem}">
                <bc:OverflowableStackPanel HorizontalAlignment="Stretch"
                                           Orientation="Horizontal" 
                                           OverflowItemCount="{Binding OverflowItemCount, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWayToSource}" >
                  <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CaptionStates">
                      <VisualState x:Name="ShowCaption" >
                        <Storyboard>
                          <DoubleAnimation Storyboard.TargetName="headerHL"  Duration="0:0:1"
                                             Storyboard.TargetProperty="MaxWidth" 
                                             To="1000" />
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerHL"
                                                   Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                              <DiscreteObjectKeyFrame.Value>
                                <Visibility>Visible</Visibility>
                              </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                      <VisualState x:Name="HideCaption"  >
                        <Storyboard>
                          <DoubleAnimation Storyboard.TargetName="headerHL"  Duration="0:0:0"
                                             Storyboard.TargetProperty="MaxWidth" To="{Binding ActualWidth, ElementName=PART_CaptionButton}"  />
                          <DoubleAnimation Storyboard.TargetName="headerHL"  Duration="0:0:1"
                                             Storyboard.TargetProperty="MaxWidth" To="0"  />
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="headerHL"
                                                   Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="00:00:1">
                              <DiscreteObjectKeyFrame.Value>
                                <Visibility>Collapsed</Visibility>
                              </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </VisualState>
                    </VisualStateGroup>
                  </VisualStateManager.VisualStateGroups>

                  <ctrls:HotTrack Grid.Column="0" Grid.Row="0"   x:Name="headerHL" bc:OverflowableStackPanel.CanOverflow="True"
                                  SelectedBorderBrush="{TemplateBinding BorderBrush}" MaxWidth="1000"
                                  BorderThickness="1,0" >

                    <StackPanel Orientation="Horizontal">
                      <StackPanel.Resources>
                        <conv:BoolToVisibilityCollapsedConverter x:Key="btvc" />
                      </StackPanel.Resources>
                      <Button Template="{StaticResource BaseButton}" x:Name="PART_CaptionButton"  
                            MaxWidth="1000"
                            >
                        <ContentPresenter x:Name="PART_Header" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"                                   
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" />
                      </Button>
                      <ctrls:HotTrack x:Name="headerToggleHL"  bc:OverflowableStackPanel.CanOverflow="True"
                                 BorderThickness="1,0,0,0"
                                 SelectedBorderBrush="Transparent"
                                 Visibility="{Binding HasItems, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource btvc}}"
                                >
                        <ctrls:DropDownList x:Name="PART_Toggle" ItemsSource="{TemplateBinding ItemsSource}"
                                  Visibility="{Binding HasItems, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource btvc}}" 
                                  SelectedValuePath="{Binding ValuePath, RelativeSource={RelativeSource TemplatedParent}}"
                                  IsDropDownOpen="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                  SelectedValue="{Binding SelectedChild, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                  ItemTemplate="{TemplateBinding MenuItemTemplate}" >
                        </ctrls:DropDownList>
                      </ctrls:HotTrack>

                    </StackPanel>
                  </ctrls:HotTrack>



                  <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" />

                </bc:OverflowableStackPanel>
                <ControlTemplate.Triggers>
                  <MultiTrigger >
                    <MultiTrigger.Conditions>
                      <Condition Property="IsChildSelected" Value="false" />
                      <Condition Property="IsCurrentSelected" Value="false" />
                    </MultiTrigger.Conditions>
                    <MultiTrigger.Setters>
                      <Setter Property="Visibility" Value="Collapsed"/>
                    </MultiTrigger.Setters>
                  </MultiTrigger>
                  <Trigger  SourceName="headerHL" Property="IsMouseDirectlyOver" Value="True">
                    <Setter TargetName="headerToggleHL" Property="IsEnabled" Value="False" />
                  </Trigger>
                  <!--<Trigger Property="IsExpanded" Value="true">
                <Setter Property="Visibility" Value="Visible"/>
            </Trigger>-->
                  <!--<Trigger Property="HasItems" Value="false">
                <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
            </Trigger>-->
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="ItemsPanel">
            <Setter.Value>
              <ItemsPanelTemplate>
                <bc:OneItemPanel />
                <!--<VirtualizingStackPanel VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Standard"  
                                            HorizontalAlignment="Stretch" Orientation="Horizontal" VerticalAlignment="Stretch" />-->
              </ItemsPanelTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="MenuItemTemplate" Value="{Binding MenuItemTemplate, RelativeSource={RelativeSource AncestorType={x:Type uc:BreadcrumbTree}}}" />
          <Style.Triggers>
            <!--This trigger is needed, because RelativeSource binding can only succeeds if the current MenuItem is already connected to its visual parent-->
            <Trigger Property="IsVisible" Value="True">
              <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
              <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            </Trigger>
          </Style.Triggers>
        </Style>
      </Setter.Value>
    </Setter>
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <bc:OneItemPanel />
          <!--<VirtualizingStackPanel VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Standard"  
                                            HorizontalAlignment="Stretch" Orientation="Horizontal" VerticalAlignment="Stretch" />-->
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type uc:BreadcrumbTree}">
          <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
            <ItemsPresenter VerticalAlignment="Center" />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>
